package jrain.fw.script.support;

import jrain.fw.script.context.ScriptContext;
import jrain.fw.script.core.Evaluator;
import jrain.fw.script.core.ExpressionEvaluator;
import jrain.fw.script.operator.Coercions;
import jrain.fw.script.tools.ELException;
import jrain.fw.script.tools.Logger;
import jrain.fw.script.tools.ScriptException;

public class ExpressionEvaluatorManager {

	private static final ExpressionEvaluator EVALUATOR = new Evaluator();

	private static final Logger logger = new Logger(System.out);

	public static String validate(String attributeName, String expression) {
		return EVALUATOR.validate(expression);
	}

	public static Object evaluate(String expression, Class<?> expectedType, ScriptContext pageContext) throws ScriptException {

		return (EVALUATOR.evaluate(expression, expectedType, pageContext));
	}

	public static Object coerce(Object value, Class<?> classe) throws ScriptException {
		try {
			return Coercions.coerce(value, classe, logger);
		} catch (ELException ex) {
			throw new ScriptException(ex);
		}
	}

}
